package com.example.dao;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.example.domain.ClassType;

/**
 * @author 袁小弘
 * @describe 班级DAO层
 * @date 2020-01-16
 */
@Repository
public interface ClassTypeDao extends JpaRepository<ClassType, Integer> {

    @Transactional
    @Modifying
    int deleteByClassTypeId(Integer classTypeId);

    List<ClassType> findByClassTypeId(Integer classTypeId);

    @Query(nativeQuery = true, value = "SELECT ct.*,c.className FROM class_type ct INNER JOIN classes c ON ct.class_Id = c.class_Id")
    List<Map<String, Object>> queryAllClassAndType();

    @Transactional
    @Modifying
    int deleteByClassTypeIdIn(List<Integer> listId);

    @Query(nativeQuery = true, value = "SELECT * FROM class_type WHERE typeName like CONCAT('%',:typeName,'%')")
    List<ClassType> findByTypeNameLike(@Param("typeName") String typeName);

    List<ClassType> findByPid(Integer pid);

    @Query(nativeQuery = true, value = "SELECT * FROM class_type")
    List<Map<String, Object>> queryAllOfTreeForm();


}
